//
//  MKTLabel.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2021/7/16.
//  Copyright © 2021 moon. All rights reserved.
//

#import "MKTLabel.h"

@implementation MKTLabel

- (void)setContentInsets:(UIEdgeInsets)contentInsets {
    if(!UIEdgeInsetsEqualToEdgeInsets(contentInsets, _contentInsets)){
        _contentInsets = contentInsets;
        [self setNeedsDisplay];
    }
}

- (void)drawTextInRect:(CGRect)rect {
    [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.contentInsets)];
}

- (CGSize)sizeThatFits:(CGSize)size {
    CGSize boundsize = size;
    UIEdgeInsets insets = self.contentInsets;
    boundsize.width = MAX(0,size.width-insets.left-insets.right);
    boundsize.height = MAX(0,size.height-insets.top-insets.bottom);
    CGSize s = [super sizeThatFits:boundsize];
    if (s.width > 0) {
        s.width += insets.left + insets.right;
    }
    if (s.height > 0) {
        s.height += insets.top + insets.bottom;
    }
    if(self.fixSuperWidth){
        s.width = size.width;
    }
    return s;
}

- (CGSize)intrinsicContentSize {
    return [self sizeThatFits:CGSizeMake(9999999, 9999999)];
}

@end
